package com.sun;

// Equals学习
public class EqualsTest {

    public static void main(String[] args) {
        // 新建两个内容相同的Person对象
        Person person1 = new Person(12, "zhangSan");
        Person person2 = new Person(12, "zhangSan");

        //System.out.println(Integer.toHexString(person1.hashCode()));
        //System.out.println(Integer.toHexString(person2.hashCode()));
        //System.out.println(person1);
        //System.out.println(person2);

        /**
         * Person对象没有重写Object类中equals()方法，所以此次调用person1.equals(person2)比较的是两个Person对象的内存地址是否相等
         * 也就是调用Object类中的equals()方法
         *
         *     public boolean equals(Object obj) {
         *         return (this == obj);
         *     }
         */
        System.out.println(person1.equals(person2));
    }

    private static class Person{
        int age;
        String name;

        public Person(int age, String name) {
            this.age = age;
            this.name = name;
        }

        @Override
        public String toString() {
            return "Person{" +
                    "age=" + age +
                    ", name='" + name + '\'' +
                    '}';
        }
    }
}
